import axios from "axios";
import service from "@/config/index";
import { API, createApis } from "../fulfill";

export const SCHEMAS = {
  getReceiptPics: new API({
    url: "/receipt/piclist",
    method: "GET"
  }),
  addWarning: new API({
    url: "/single/refreshere/${orderId}",
    method: "PUT"
  }),
  lockSign: new API({
    url: "/now/sign/${orderId}",
    method: "PUT"
  }),
  syncSign: new API({
    url: "/sync/synchronize",
    method: "PUT"
  }),
  checkContractNo: new API({
    url: "/checkContractNo/${contractNo}",
    method: "GET"
  }),
  addRemark: new API({
    url: "/desc",
    method: "PUT"
  }),
  addSignScore: new API({
    url: "/score",
    method: "PUT"
  }),
  updateTrackTime: new API({
    url: "/additional/update/time",
    method: "PUT"
  }),
  batchClose: new API({
    url: "/batch/close",
    method: "POST"
  }),
  close: new API({
    url: "/close",
    method: "PUT"
  }),
  receipt: new API({
    url: "/receipt",
    method: "PUT"
  }),
  receiptLose: new API({
    url: "/receipt/lose",
    method: "PUT"
  }),
  receiptReview: new API({
    url: "/orderGoods/receipt",
    method: "PUT"
  }),
  batchReceipt: new API({
    url: "/receipt/batch",
    method: "POST"
  }),
  sign: new API({
    url: "/sign",
    method: "PUT"
  }),
  batchSign: new API({
    url: "/sign/batch",
    method: "POST"
  }),
  createOrder: new API({
    url: "",
    method: "POST"
  }),
  updateOrder: new API({
    url: "/${orderId}",
    method: "PUT"
  }),
  getOrderById: new API({
    url: "/${orderId}",
    method: "GET"
  }),
  listOrderReceiptGoods: new API({
    url: "/goods/list/receipt",
    method: "POST"
  }),
  listOrderSignGoods: new API({
    url: "/goods/list/sign",
    method: "POST"
  }),
  listOrderEndGoods: new API({
    url: "/goods/list/done",
    method: "POST"
  }),
  addOrderGoods: new API({
    url: "/orderGoods/${type}/${orderGoodsId}",
    method: "POST"
  }),
  getOriginOrderById: new API({
    url: "/original/data/${orderId}",
    method: "GET"
  }),
  listOrderTaskLogs: new API({
    url: "/notice/task",
    method: "POST"
  }),
  listOrderReadTaskLogs: new API({
    url: "/notice/task/mark/read",
    method: "POST"
  }),
  getOrderTracks: new API({
    url: "/additional/transport/list/${orderId}",
    method: "GET"
  }),
  listOrderSignExceptions: new API({
    url: "/orderGoods/sign/goods/record",
    method: "POST"
  }),
  listOrderReceiptExceptions: new API({
    url: "/orderGoods/receipt/goods/record",
    method: "POST"
  }),
  getGoodsTrackSearch: new API({
    url: "/search",
    method: "POST"
  }),
  orderPreview: new API({
    url: '/${orderId}',
    method: 'GET'
  }),
  ordeAttachmentList: new API({
    url: '/attachment/search',
    method: 'POST'
  }),
  getGoodsSummaries: new API({
    url: '/search/sum',
    method: 'POST'
  }),
  setTemperatureHumidity: new API({
    url: '/restrict',
    method: 'PUT'
  }),
  createOrderDraft: new API({
    url: '/draft',
    method: 'POST'
  }),
  updateOrderDraft: new API({
    url: "/draft/${draftId}",
    method: 'PUT'
  }),
  getOrderDraft: new API({
    url: '/draft/${draftId}',
    method: 'GET'
  }),
  deleteOrderDraft: new API({
    url: '/draft/${draftId}',
    method: 'DELETE'
  }),
  getOrderFollowList: new API({
    url: '/follow/list',
    method: 'POST'
  }),
  orderDeviceTrace: new API({
    url: '/trace/device',
    method: 'POST'
  }),
  restrictDevice: new API({
    url: '/device/track/restrict',
    method: 'POST'
  })
};
const APIS = createApis(service.serviceOrder, SCHEMAS);

const URLS = {
  PARSE_ADDRESS: `${service.serviceArea}/parse`,
  GET_CREATE_CONFIG: `${service.serviceBasic}/customer/order/defaults`,
  SET_CREATE_CONFIG: `${service.serviceBasic}/customer/order/defaults`
};
export default {
  // 订单导入
  importExcel (file) {
    return axios.post(`${service.serviceOrder}/excel/read`, file, {
      timeout: 200000
    });
  },
  // 提交订单导入
  submitImportExcel (params) {
    return axios.post(`${service.serviceOrder}/excel/submit`, params);
  },
  // 获取客户配置信息
  getCreateConfig (id) {
    return axios.get(`${URLS.GET_CREATE_CONFIG}/${id}`);
  },
  // 设置创建订单配置信息
  setCreateConfig (params) {
    return axios.post(URLS.SET_CREATE_CONFIG, params);
  },
  modeApi (type, code) {
    return axios.get(`/ere/track/getThirdTrack/${type}/${code}`);
  },
  deviceApi (page = 1, pageSize = 100, devCode) {
    return axios.get(`/ere/device/list/${page}/${pageSize}/${devCode}`);
  },
  showDeviceApi (devCode) {
    return axios.get(`/ere/device/getByDevCode/${devCode}`);
  },
  // 获取收发货地址经纬度
  parseAddress (params) {
    return axios.post(URLS.PARSE_ADDRESS, params);
  },
  analysisAddress (params) {
    return axios.post(`${service.serviceArea}/region/address/analysis`, params);
  },
  // 创建订单
  createOrder (data) {
    return APIS.createOrder({ data });
  },
  orderDetailsApi (orderId) {
    return APIS.getOrderById({ variables: { orderId } });
  },
  orderGoodsReceiptApi (data) {
    // return axios.post(`${service.serviceOrder}/goods/list/receipt`, params)
    return APIS.listOrderReceiptGoods({ data });
  },
  orderGoodsSignApi (data) {
    // return axios.post(`${service.serviceOrder}/goods/list/sign`, params)
    return APIS.listOrderSignGoods({ data });
  },
  orderGoodsListApi (data) {
    // return axios.post(`${service.serviceOrder}/goods/list/done`, params)
    return APIS.listOrderEndGoods({ data });
  },
  orderScoreApi (data) {
    return APIS.addSignScore({ data });
  },
  goodsSaveApi (type, data) {
    // return axios.post(`${service.serviceOrder}/orderGoods/${type}`, params)
    return APIS.addOrderGoods({ variables: { type }, data });
  },
  goodsDeleteApi (type, orderGoodsId) {
    // return axios.put(`${service.serviceOrder}/orderGoods/${type}/${orderGoodsId}`)
    return APIS.removeOrderGoods({ variables: { type, orderGoodsId } });
  },
  // 修改订单
  updateOrder (orderId, data) {
    // return axios.put(`${service.serviceOrder}/${orderId}`, params)
    return APIS.updateOrder({ variables: { orderId }, data });
  },
  // 回单
  receipt (data) {
    // return axios.post(`${service.serviceOrder}/receipt`, params)
    return APIS.receipt({ data });
  },
  // 订单批量回单
  receiptBatch (data) {
    // return axios.post(`${service.serviceOrder}/receipt/batch`, params)
    return APIS.batchReceipt({ data });
  },
  // 签收
  sign (data) {
    // return axios.post(`${service.serviceOrder}/sign`, params)
    return APIS.sign({ data });
  },
  // 获取详情（修改、复制）
  orderDetail (orderId) {
    // return axios.get(`${service.serviceOrder}/original/data/${orderId}`)
    return APIS.getOriginOrderById({ variables: { orderId } });
  },
  // 获取批量操作结果
  getTaskLog () {
    // return axios.post(`${service.serviceOrder}/notice/task`, {})
    return APIS.listOrderTaskLogs();
  },
  // 获取批量操作结果
  getReadTaskLog () {
    // return axios.post(`${service.serviceOrder}/notice/task/mark/read`, {})
    return APIS.listOrderReadTaskLogs();
  },
  //验证重复合同编号
  validateRepeatContractNo (data) {
    return axios.get(`${service.serviceOrder}/checkContractNo`, {
      params: { ...data }
    })
    // return APIS.checkContractNo({ variables });
  },
  // 物品签收异常登记记录
  signGoodsRecord (data) {
    // return axios.post(`${service.serviceOrder}/orderGoods/sign/goods/record`, params)
    return APIS.listOrderSignExceptions({ data });
  },
  // 物品回单异常登记记录
  receiptGoodsRecord (data) {
    // return axios.post(`${service.serviceOrder}/orderGoods/receipt/goods/record`, params)
    return APIS.listOrderReceiptExceptions({ data });
  },
  // 货物跟踪列表
  getOrderSearch (data) {
    return APIS.getGoodsTrackSearch({ data });
  },
  // 订单预览
  orderPreview (orderId) {
    return APIS.orderPreview({ variables: { orderId } })
  },
  // 订单附件列表
  ordeAttachmentList (data) {
    return APIS.ordeAttachmentList({ data })
  },
  getGoodsSummaries (data) {
    return APIS.getGoodsSummaries({ data })
  },
  // 温湿度信息
  temperatureHumidity (data) {
    return axios.get(`${service.serviceOrder}/device/trend`, {
      params: { ...data }
    })
  },
  // 设置最高最小温湿度值
  setTemperatureHumidity (data) {
    return APIS.setTemperatureHumidity({ data })
  },
  // 温湿度报告下载PDF预览
  previewPdf (params) {
    return axios.post(`/ere/track/exportOrderStatus`, params);
  },
  // 温湿度节点小地图获取位置列表
  getPosition (params) {
    return axios.post(`/ere/position/getPosition`, params);
  },
  // 货物跟踪设备信息
  orderDeviceTrace (data) {
    return APIS.orderDeviceTrace({ data })
  },

  // 创建订单草稿
  createOrderDraft (data) {
    return APIS.createOrderDraft({ data })
  },
  // 修改订单草稿
  updateOrderDraft (data) {
    return APIS.updateOrderDraft({ variables: { draftId: data.draftId }, data });
  },
  // 查看订单草稿
  getOrderDraft (draftId) {
    return APIS.getOrderDraft({ variables: { draftId } });
  },
  // 删除订单草稿
  deleteOrderDraft (data) {
    return APIS.deleteOrderDraft({ variables: { draftId: data.draftId }, data });
  },
  // 查询订单跟进历史
  getOrderFollowList (data) {
    return APIS.getOrderFollowList({ data })
  },
  // 批量绑定不共用跟踪方式 识别设备是否可以绑定
  restrictDevice (data) {
    return APIS.restrictDevice({ data })
  }
};
